# Maintainer: Krassy Boykinov <kboykinov@teamcentrixx.com>
pkgname=gst-plugins-rs
pkgver=0.13.2
pkgrel=0
pkgdesc="Gstreamer rust plugins"
url="https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs"
# loongarch64: blocked by nix 0.23.2
# s390x: fails to build
arch="all !loongarch64 !s390x"
license="MIT AND Apache-2.0 AND MPL-2.0 AND LGPL-2.1-or-later"
makedepends="
	cargo
	cargo-c
	dav1d-dev
	gst-plugins-bad-dev
	gst-plugins-base-dev
	gtk4.0-dev
	libsodium-dev
	meson
	nasm
	openssl-dev
	"
subpackages="$pkgname-dev"
_plugins="cdg
	claxon
	dav1d
	fallbackswitch
	ffv1
	fmp4
	gif
	gopbuffer
	gtk4
	hlssink3
	hsv
	json
	lewton
	livesync
	mp4
	mpegtslive
	ndi
	originalbuffer
	quinn
	raptorq
	rav1e
	regex
	reqwest
	rsaudiofx
	rsclosedcaption
	rsfile
	rsflv
	rsinter
	rsonvif
	rspng
	rsrtp
	rsrtsp
	rstracers
	rsvideofx
	rswebp
	sodium
	spotify
	textahead
	textwrap
	threadshare
	togglerecord
	uriplaylistbin
	webrtchttp
	"
source="https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/archive/$pkgver/gst-plugins-rs-$pkgver.tar.gz
	dylib.patch
	"
options="net !check" # they don't run

export SODIUM_USE_PKG_CONFIG=1

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

case "$CARCH" in
	# Some plugins run out of memory compiling, disable them
	armhf|armv7|x86)
		_opts="-Daws=disabled -Dwebrtc=disabled"
		;;
	*)
		_plugins="$_plugins aws rswebrtc"
		# tools is currently only used when webrtc is enabled
		subpackages="$subpackages $pkgname-tools"
		;;
esac

_sub_plugin() {
	local n=${subpkgname##"$pkgname"-}
	pkgdesc="Gstreamer rust plugin for $n"
	amove usr/lib/gstreamer-1.0/libgst"$n".so
}

for _plugin in $_plugins; do
	subpackages="$subpackages $pkgname-$_plugin:_sub_plugin"
done

build() {
	export CARGO_PROFILE_RELEASE_OPT_LEVEL=3
	abuild-meson \
		--buildtype=release \
		$_opts \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

tools() {
	amove usr/bin
}

sha512sums="
41500fb8c627d7942e371dd123c58cbf0af6b054d4fef3213996d297e35887a5eb5f2e5744688bdcbbbac9d69bcbc5ca229a042eb1de7968afade1a7040f0114  gst-plugins-rs-0.13.2.tar.gz
5f354a7776859f62a235947b5a31779688bc681f3c47c3fbf85806c8a12f68023a731067c958e40dfd580af591ea271e4e5184ef3b45a193c9b855486c64fef0  dylib.patch
"
